using System;
using System.Collections;

namespace FwkLight.CodeExtensions
{
  public class NameValueCollectionItemDictionary : IItemDictionary
  {
    private readonly Hashtable dictionary;


    public NameValueCollectionItemDictionary ( Hashtable payload )
    {
      dictionary = payload;
    }

    public NameValueCollectionItemDictionary()
    {
      dictionary = new Hashtable();
    }

    #region IItemDictionary Members

    public void Add<ItemToPutIn>(IItemKey<ItemToPutIn> key, ItemToPutIn item)
    {
      dictionary.Add(key.Key, item);
    }

    public Item Get<Item>(IItemKey<Item> key)
    {
      var x = dictionary[key.Key];
      if (x != null)
        return (Item)x ;
      return default (Item);
    }

    #endregion

    public bool Contains<Item>(IItemKey<Item> key)
    {
      return (dictionary.Contains(key.Key));
    }

    public void Remove<ItemToPutIn>(IItemKey<ItemToPutIn> key)
    {
      dictionary.Remove(key.Key);
    }

    public void Clear()
    {
      dictionary.Clear();
    }
  }
}